var addData_student = function () {
    var loadDiv = load("#body", 999999);
    console.log($(".SHinput").children("input"));
    $(".SHinput").children("input").text("");
    $.ajax({
        url: "student/findOne",
        type: "post",
        data: {
            "id": localStorage['id'],
            "token": localStorage["token"]
        },
        success: function (data) {
            console.log(data);
            if (data.code === 200) {
                console.log($("#name"));
                $("#name").val(data.data.name);
                $("#qq").val(data.data.qq);
                $("#dorm").val(data.data.dorm);
                $("#clas").val(data.data.clas);
                $("#email").val(data.data.email);
                $("#phone").val(data.data.phone);
            } else {
                errorMessage(data.msg);
            }
            load_close(loadDiv);
        }
    })
};

$("#changeSelf_student").click(function () {
    var loadDiv = load("#body", 99999);
    var phone = $("#phone").val();
    var qq = $("#qq").val();
    var email = $("#email").val();
    $.ajax({
        url: "student/update",
        type: "post",
        data: {
            "token": localStorage['token'],
            "qq": qq,
            "phone": phone,
            "email": email,
            "id": localStorage['id']
        },
        success: function (data) {
            console.log(data);
            if (data.code == 200) {
                message("修改成功!");
                var path = "page/student/home";
                $("#body").load(path);
            } else {
                errorMessage(data.msg);
            }
            load_close(loadDiv);

        }

    })
});
$("#qq").blur(function () {
    var test = /^[1-9][0-9]{4,10}$/;
    var qq = $(this).val();
    if (!test.test(qq)) {
        $(this).parent().children(".errorMsg").text("请输入正确的qq号");
    } else {
        $(this).parent().children(".errorMsg").empty();
    }
    if (qq == "") {
        $(this).parent().children(".errorMsg").text("qq号不能为空");
    }
});
$("#phone").blur(function () {
    var test = /^1[34578]\d{9}$/;
    var phone = $(this).val();
    if (!test.test(phone)) {
        $(this).parent().children(".errorMsg").text("请输入正确的手机号");
    } else {
        $(this).parent().children(".errorMsg").empty();
    }
    if (phone == "") {
        $(this).parent().children(".errorMsg").text("手机号不能为空");
    }
});

$("#email").blur(function () {
    var test = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
    var email = $(this).val();
    if (!test.test(email)) {
        $(this).parent().children(".errorMsg").text("请输入正确的邮箱");
    } else {
        $(this).parent().children(".errorMsg").empty();
    }
    if (email == "") {
        $(this).parent().children(".errorMsg").text("邮箱不能为空");
    }
});

$("#phone, #email,#qq").blur(function () {
    if ($("#phone").parent().children(".errorMsg").text() != "" || $("#email").parent().children(".errorMsg").text() != "" || $("#qq").parent().children(".errorMsg").text() != "") {
        $("#changeSelf_student").attr("disabled", "disabled");
        $("#changeSelf_student").addClass("button_cannot");
    } else {
        $("#changeSelf_student").removeAttr("disabled");
        $("#changeSelf_student").removeClass("button_cannot");
    }
});

